import pymysql


# 添加课程信息，输入课程信息格式为：Cno,Cname,Tno
def addCourse(cs):
    courseInfo = input()
    # **********begin********** #
    sql = """
        insert into Course(Cno, Cname, Tno) values(%s, %s, %s);
    """
    cs.execute(sql, courseInfo.split(','))
    
    
    
    # **********end********** #


# 修改课程信息（通过课程编号修改课程名称），输入新课程信息格式为：Cno,Cname
def updateCourse(cs):
    courseInfo = input()
    # **********begin********** #
    sql = """
        update Course
        set Cname=%s
        where Cno=%s;
    """
    # print(courseInfo.split(',')[::-1])
    cs.execute(sql, courseInfo.split(',')[::-1])
   
   
    # **********end********** #


# 查询课程信息（通过课程编号查询课程信息），输入课程编号 Cno
# 将课程信息打印到控制台
def findCourseByCno(cs):
    courseId = input()
    # **********begin********** #
    sql = """
        select * from Course where Cno=%s;
    """
    cs.execute(sql, courseId)
    print(cs.fetchall())
   
   
    # **********end********** #


# 删除课程信息（通过课程编号删除课程信息），输入课程编号 Cno
def deleteCourse(cs):
    courseId = input()
    # **********begin********** #
    sql = """
        delete from Course
        where Cno=%s;
    """

    cs.execute(sql, courseId)
    
    
    # **********end********** #


# 通过教师名称查询课程名称并将其打印到控制台,输入教师名称 Tname
# 打印格式为：课程名  （一个课程名一行，不含其它字符）
def findCourseByTeacherName(cs):
    tname = input()
    # **********begin********** #
    sql = """
        select Cname from Course join Teacher on Course.Tno=Teacher.Tno
        where Teacher.Tname=%s;
    """
    cs.execute(sql, tname)
    # print(cs.fetchall())
    for i in cs.fetchall():
        print(i[0])
    
    
    # **********end********** #


# 通过课程名称查询教师名称并将其打印到控制台，输出课程名称 Cname
# 打印格式为：教师名  （一个教师名一行，不含其它字符）
def selectTeacherByCname(cs):
    cname = input()
    # **********begin********** #
    sql = """
        select Tname from Course join Teacher on Teacher.Tno=Course.Tno
        where Course.cname=%s;
    """
    cs.execute(sql, cname)

    for i in cs.fetchall():
        print(i[0])
   
   
    # **********end********** #

def Test(cs):
    sql = "select * from Course"
    cs.execute(sql)
    courseInfo = cs.fetchall()
    print(courseInfo)


if __name__ == '__main__':
    conn = pymysql.connect(host='localhost', port=3306,
                           user='root', passwd='123123', db="nudt", charset='utf8')
    command = input()
    cs = conn.cursor()
    if command == '01':
        addCourse(cs)
    elif command == '02':
        updateCourse(cs)
    elif command == '03':
        findCourseByCno(cs)
    elif command == '04':
        deleteCourse(cs)
    elif command == '05':
        findCourseByTeacherName(cs)
    elif command == '06':
        selectTeacherByCname(cs)
    conn.commit()
    Test(cs)
    cs.close()
    conn.close()
